package com.job.search.controller;

import com.job.client.common.result.ResponseResult;
import com.job.client.model.company.dto.CompanyEsDto;
import com.job.client.model.company.pojo.Company;
import com.job.search.dto.CompanySearchDto;
import com.job.search.dto.PostsSearchDto;
import com.job.search.service.SearchCompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/api/v1/search/company")
@RestController
@Api(tags = "公司搜索服务接口文档")
public class SearchCompanyController {
    @Autowired
    private SearchCompanyService companyService;
    @PostMapping("/add")
    @ApiOperation("根据id向company插入数据")
    public ResponseResult addCompany(@RequestBody CompanyEsDto company){
        return companyService.addCompany(company);
    }
    @PostMapping("/bulk/add")
    @ApiOperation("根据id批量向company插入数据")
    public ResponseResult blkAddCompany(@RequestBody List<CompanyEsDto> companyList){
        return companyService.blkAddCompany(companyList);
    }

    @GetMapping("/{companyId}")
    @ApiOperation("根据id查询company")
    public ResponseResult getById(@PathVariable String companyId){
        return companyService.getById(companyId);
    }

    @DeleteMapping("/{companyId}")
    @ApiOperation("根据id删除company中的数据")
    public ResponseResult deleteById(@PathVariable String companyId){
        return companyService.deleteById(companyId);
    }

    @PostMapping("/update")
    @ApiOperation("根据companyId修改数据,null的数据自动跳过")
    public ResponseResult modifyPartialById(@RequestBody CompanyEsDto company){
        return companyService.modifyPartialById(company);
    }

    @PostMapping("/search")
    @ApiOperation("关键字分词查询")
    public ResponseResult search(@RequestBody CompanySearchDto dto){
        return companyService.search(dto);
    }

    @PostMapping("/search/query")
    @ApiOperation("关键字精确查询")
    public ResponseResult searchQuery(@RequestBody PostsSearchDto dto){
        return companyService.searchQuery(dto);
    }

    @PostMapping("/search/highlight")
    @ApiOperation("关键字分词查询，并把关键字高亮显示")
    public ResponseResult searchHighlight(@RequestBody CompanySearchDto dto){
        return companyService.searchHighlight(dto);
    }
}
